package cn.itcast.dao.impl;

import cn.itcast.dao.BookDao;
import cn.itcast.pojo.Book;
import cn.itcast.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class BookDaoImpl implements BookDao {
    private JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public List<Book> findAll() {
        List<Book> bookList = jdbcTemplate.query("select * from bookmanage", new BeanPropertyRowMapper<>(Book.class));
        return bookList;
    }

    @Override
    public void delById(int id) {
      jdbcTemplate.update("delete from bookmanage where id=?", id);
    }

    @Override
    public void addBood(Book book) {
        jdbcTemplate.update("insert into bookmanage values (null,?,?,?,?)",book.getName(),book.getAuthor(),book.getTime(),book.getType());
    }
}
